package co.yixiang.huiMin.controller;


import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.huiMin.entity.VipInfo;
import co.yixiang.huiMin.service.VipInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-07-11
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/vipInfo")
public class VipInfoController  {

    @Resource
    private VipInfoService vipInfoService;
    @ApiOperation("查询所有Vip信息")

    @GetMapping
    public ResponseEntity inquiryVipInfo(){

        List<VipInfo> list = vipInfoService.list();
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message",list);
        return ResponseEntity.ok(resultMap);
    }

    @ApiOperation("查询Vip信息")
    @GetMapping("inquiryVipInfoById")
    public ResponseEntity inquiryVipInfo(Integer vipId){

        VipInfo byId = vipInfoService.getById(vipId);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message",byId);
        return ResponseEntity.ok(resultMap);
    }

    @ApiOperation("修改Vip信息")

    @PostMapping
    public ResponseEntity inquiryVipInfo(@RequestBody VipInfo vipInfo){
        Map<String, Object> resultMap = new HashMap<>();
        if (vipInfo.getVipId() == null) {
            resultMap.put("code",300);
            resultMap.put("message","请选择修改的VIP");
            return ResponseEntity.ok(resultMap);
        }
        resultMap.put("code",200);
        resultMap.put("message",vipInfoService.saveOrUpdate(vipInfo)?"修改成功":"修改失败");
        return ResponseEntity.ok(resultMap);
    }

}

